home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************/
- /* */
- /* Program name: cdio */
- /* */
- /* Purpose: To provide standard console device interface routines */
- /* such as Open, GetChar, PutChar, etc. */
- /* */
- /* Arguments: (window) - The window to associate the console */
- /* device with. Used in CDOpen. */
- /* (character) - The char to output. Used in CDPutChar */
- /* (string) - The string to output. Used in CDPutStr */
- /* */
- /* Programer: Stan Shepard */
- /* */
- /* Date Released: 27 Jan 1996 19:15:00 */
- /* */
- /*********************************************************************/
-
- extern int CDOpen(struct Window *);
- extern void CDClose(void);
- extern void CDPutChar(char);
- extern void CDPutStr(const char *);
- extern void CDPutStrLength(const char *string, size_t Length);
-
-
- struct IOStdReq consoleIO;
- struct MsgPort consoleMsgPort;
- BOOL portda = FALSE, ConsoleOpen = FALSE;
-
-
- int CDOpen(struct Window *window)
- {
- int error;
-
- assert(!ConsoleOpen);
-
- /* Open the console device */
- consoleIO.io_Data = (APTR) window;
- consoleIO.io_Length = sizeof(*window);
- if ((error = OpenDevice((UBYTE *)"console.device", 0, (struct IORequest *) &consoleIO, 0)) != 0)
- {
- printf("CDInit OpenDevice error: %d.\n", error);
- return(error);
- }
- ConsoleOpen = TRUE;
-
- /* Set up the message port in the I/O request */
- consoleMsgPort.mp_Node.ln_Type = NT_MSGPORT;
- consoleMsgPort.mp_Flags = 0;
- consoleMsgPort.mp_SigBit = AllocSignal(-1);
- consoleMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL);
- portda = TRUE;
- consoleIO.io_Message.mn_ReplyPort = &consoleMsgPort;
-
- return(0);
- }
-
-
- void CDClose()
- {
- if (portda)
- {
- FreeSignal(consoleMsgPort.mp_SigBit);
- portda = FALSE;
- }
- if (ConsoleOpen)
- {
- CloseDevice((struct IORequest *) &consoleIO);
- ConsoleOpen = FALSE;
- }
- }
-
-
- void CDPutChar(char character)
- {
- assert(ConsoleOpen);
-
- consoleIO.io_Command = CMD_WRITE;
- consoleIO.io_Data = (APTR) &character;
- consoleIO.io_Length = 1;
- DoIO((struct IORequest *) &consoleIO);
- }
-
-
- /* NULL terminated string to output */
- void CDPutStr(const char *string)
- {
- assert(ConsoleOpen);
-
- consoleIO.io_Command = CMD_WRITE;
- consoleIO.io_Data = (APTR) string;
- consoleIO.io_Length = -1;
- DoIO((struct IORequest *) &consoleIO);
- }
-
-
- /* NULL terminated string to output */
- void CDPutStrLength(const char *string, size_t Length)
- {
- assert(ConsoleOpen);
-
- consoleIO.io_Command = CMD_WRITE;
- consoleIO.io_Data = (APTR) string;
- consoleIO.io_Length = Length;
- DoIO((struct IORequest *) &consoleIO);
- }
-
-
-